package com.jdew.thkj.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.RequiresApi;


public class NotificationsUtils {

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public static void checkNotificationEnable(final Context context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage("检测到您还没有打开通知是否去打开");
        builder.setPositiveButton("去打开", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                toSetting(context);
            }
        });
        builder.setNegativeButton("暂不打开", null);
        builder.show();

    }

    private static void toSetting(Context context) {
        Intent localIntent = new Intent();
        localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));

        context.startActivity(localIntent);
    }
}
